/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

define(['adminapp'], function ($app) {
    $app.navactive('vote_index');

    var action_tpl = Handlebars.compile($("#action_template").html());
    var opt_tpl = Handlebars.compile($("#opt_template").html());

    $app.listtable({
        'sAjaxSource' : g.ctx + "admin/vote/vote/list",
        'bSort'       : true,
        'bAutoWidth'  : true,
        'iDisplayLength': 5,
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'title', "bSortable": false},
            {'mDataProp': 'opt', "bSortable": false},
            {'mDataProp': 'begin_time' },
            {'mDataProp': 'end_time' },
            {'mDataProp': 'sequence' },
            {'mDataProp': 'state' }
        ],
        'aoColumnDefs': [
            {
                'aTargets': [3],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    var opt = full.opt;
                    var split = opt.split("{}");
                    var optV = {opt: split};
                    return opt_tpl(optV);
                }
            },
            {
                'aTargets': [7],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    if (full['state'] == 1) {
                        return '进行中';
                    } else {
                        return '停用';
                    }
                }
            },
            {
                'aTargets': [8],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'data-list');

    $('#currency_form').ajaxForm({
        dataType:  'json',
        beforeSubmit: function (formData, jqForm, options) {

        },
        success     : function (responseText, statusText) {
            if(responseText.status == 'OK'){
                bootbox.alert('设置成功!')
            } else{
                bootbox.alert(responseText.message)
            }
        }
    });

});

